// pages/comment/comment.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    good_id: 0,
    token: '',
    none: false,//判断是否有评论，没有评论就显示
    have: false,
    info: [],
    list: {
      icon: '',
      info: "",
      nick_name: "",
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#2BBDCA',
      animation: {
        duration: 400,
        timingFunc: 'easeIn'
      }
    })
    console.log(options)
    wx.getStorage({
      key: 'token',
      success(res) {
        console.log(res)
        that.data.token = res.data
        that.data.good_id = options.indexArr
        that.setData({
          token: res.data,
          good_id: options.indexArr
        })
        wx.request({
          method: "post",
          url: 'http://api_devs.wanxikeji.cn/api/commentList',
          data:{
            token:that.data.token,
            good_id:that.data.good_id
         
          },success(res){
            console.log(res)
            if (res.data.data.list.length == 0) {
              that.data.none = true
              that.data.have = false
              that.setData({
                none: true,
                have: false
              })
            } else {
              that.data.none = false
              that.data.have = true
              that.setData({
                none: false,
                have: true
              })
              for (let i = 0; i < res.data.data.list.length; i++) {
                if (res.data.data.list[i].icon == null) {
                  that.data.list.icon = "http://api_devs.wanxikeji.cn/app/pic/20210325/20210325063921561.jpg"
                } else {
                  that.data.list.icon = res.data.data.list[i].icon
                }
                that.data.list.info = res.data.data.list[i].info
                if (res.data.data.list[i].nick_name == null) {
                  that.data.list.nick_name = '匿名'
                } else {
                  that.data.list.nick_name = res.data.data.list[i].nick_name
                }

                that.data.info.push(that.data.list)
                that.setData({
                  info: that.data.info
                })
              }
              console.log(that.data.info)

            }
          }
        })
      }
    })


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})